package com.yyfax.pay.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.framework.yyfax.BaseEnum;

/**
 * 查询类型
 * 
 * @author buyi
 * @date 2017-04-12 20:06:18
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public final class QueryTypeEnum extends BaseEnum<String> {

	/** 枚举集合 */
	protected static final Map<String, QueryTypeEnum> values = new HashMap<>();

	public static final String ENUM_KEY = "QUERY_TYPE";

	/** 主动查询*/
	public static final QueryTypeEnum INITIATIVE = QueryTypeEnum.build("INITIATIVE", "1", "主动查询");

	public static final QueryTypeEnum AUTO = QueryTypeEnum.build("AUTO", "2", "自动查询");

	/**
	 * 构造函数
	 */
	private QueryTypeEnum(String name, String value, String remark) {
		super(name, value, remark);
	}

	public static List<QueryTypeEnum> values() {
		return new ArrayList<QueryTypeEnum>(values.values());
	}

	/**
	 * 不存在则添加,存在则更新(用于数据库加载时)
	 * 
	 * @author jiangmy
	 * @date 2016-12-05 19:31:30
	 * @param name
	 * @param value
	 * @param remark
	 * @return
	 */
	public static final QueryTypeEnum build(String name, String value, String remark) {
		QueryTypeEnum e = values.get(name);
		if (e == null) {
			e = new QueryTypeEnum(name, value, remark);
			values.put(name, e);
		} else {
			e.value = value;
			e.remark = remark;
		}
		return e;
	}

	public static final QueryTypeEnum fromValue(String value) {
		for (QueryTypeEnum e : values.values()) {
			if (StringUtils.equals(value, e.getValue())) {
				return e;
			}
		}
		return null;

	}
}
